package com.jiazhong.basic.shuxin.design.观察者模式;

import java.util.ArrayList;
import java.util.List;

// 彩票的主题
public class LotteryTicketSubject implements Subject {

    private List<Observer> observers = new ArrayList<>();

    private int number;

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        number = (int) (Math.random() * 33 + 1);
        for (Observer observer : observers) {
            observer.update(number);
        }
    }
}
